/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class Test_ctrl_AmendmentSelectionClass {

    static testMethod void myUnitTest() 
    {
        // TO DO: implement unit test
        
        
        Location__c locationObject = new Location__c();
        locationObject.Name = 'Test Location Vacant3';
        locationObject.Location_Type__c = 'Land';
        locationObject.Rental_Rate__c = 18000;
        locationObject.Visa_Quota__c = 5;
        insert locationObject;
        
        /*Location__c locationObject1 = new Location__c();
        locationObject1.Name = 'Test Location Vacant';
        locationObject1.Location_Type__c = 'Land';
        locationObject1.Rental_Rate__c = 18000;
        locationObject1.Visa_Quota__c = 5;
        insert locationObject1;*/
        
        Location__c locationObject2 = new Location__c();
        locationObject2.Name = 'Test Land434543';
        locationObject2.Location_Type__c = 'Land';
        locationObject2.Rental_Rate__c = 18000;
        locationObject2.Visa_Quota__c = 5;
        insert locationObject2;
               
        //Account Object Record...
        Account accountObject = new Account();
        accountObject.Name = 'Test Account';
        accountObject.License_Application_Step__c = 'Record Created';
        accountObject.License_Application_Type__c = 'New License';
        accountObject.Activity__c = 'Industrial';
        accountObject.License_Issue_Date__c = system.today();
        accountObject.License_Expiry_Date__c = System.Today().addYears(1);
        accountObject.Amendment_Change_Location__c = locationObject.Id;
        accountObject.Dummy_Activity__c = 'Services';
        accountObject.Master_Account_Flag__c = true;
        //accountObject.Residence_Visa_Quota_Used__c = 12;
        insert accountObject;
                
         //For Contact Object Records...
        Contact contactObject1 = new Contact();
        contactObject1.LastName = 'Test 1 Manager';
        contactObject1.AccountId = accountObject.id;
        contactObject1.Contact_Type__c = 'Shareholder';
        insert contactObject1;
        
        Contact contactObject2 = new Contact();
        contactObject2.LastName = 'Test 2 Shareholder';
        contactObject2.AccountId = accountObject.id;
        contactObject2.Contact_Type__c = 'Shareholder';
        insert contactObject2;
        
        //For Share Ownership Object Records...
        Share_Ownership__c shareOwnerObject1 = new Share_Ownership__c();
        shareOwnerObject1.Company__c = accountObject.Id;
        shareOwnerObject1.Shareholder__c = contactObject1.id;
        shareOwnerObject1.Ownership__c = 50;
        insert shareOwnerObject1;
        
        Share_Ownership__c shareOwnerObject2 = new Share_Ownership__c();
        shareOwnerObject2.Company__c = accountObject.Id;
        shareOwnerObject2.Ownership__c = 50;
        shareOwnerObject2.Shareholder__c = contactObject2.id;
        insert shareOwnerObject2;
                
        //For Tenancy Object Records...
        RecordType tenancyRecordType = [select Id,IsActive,SObjectType,DeveloperName from RecordType where DeveloperName = 'New_Tenancy_Contract' AND SObjectType = 'Tenancy_Contract__c'];
        Tenancy_Contract__c tenancyObject = new Tenancy_Contract__c();
        tenancyObject.Location__c = locationObject2.id;
        tenancyObject.RecordTypeId = tenancyRecordType.id;
        tenancyObject.Tenant__c = accountObject.id;
        tenancyObject.Tenancy_Contract_Start_Date__c = accountObject.License_Issue_Date__c;
        tenancyObject.Tenancy_Contract_Expiry_Date__c = date.TODAY().addyears(1).adddays(-1);
        insert tenancyObject;
        
        //For Update the Location with the current Locaiton...
        locationObject2.Current_Tenancy_Contract__c = tenancyObject.Id;
        update locationObject2;
        
        //Sub Activity Object Record...
        Sub_Activity__c subActivityObject = new Sub_Activity__c();
        subActivityObject.Activity_Type__c = 'Manufacturing';
        subActivityObject.Name = 'Test Activity';
        insert subActivityObject;
        
        //Sub Activity Object Record...
        Sub_Activity__c subActivityObject1 = new Sub_Activity__c();
        subActivityObject1.Activity_Type__c = 'Manufacturing';
        subActivityObject1.Name = 'Test Activity1';
        insert subActivityObject1;
        
        //For Account Activity Object Records FOR EDIT...
        Account_Activity__c accountActivityObject = new Account_Activity__c();
        accountActivityObject.Account__c = accountObject.Id;
        accountActivityObject.Activity__c = subActivityObject.Id; 
        accountActivityObject.Active__c = true;
        insert accountActivityObject;
        
         //For Account Activity Object Records FOR DELETE...
        Account_Activity__c accountActivityObject1 = new Account_Activity__c();
        accountActivityObject1.Account__c = accountObject.Id;
        accountActivityObject1.Activity__c = subActivityObject.Id; 
        accountActivityObject1.Active__c = true;
        insert accountActivityObject1;
        
        
        
        //Now Calling the Class...
        PageReference pageRef = null;
        
        ApexPages.StandardController accountExtendedObject = new ApexPages.StandardController(accountObject);
        ApexPages.CurrentPage().getParameters().put('accountId',accountObject.id);
        
        ctrl_AmendmentSelectionClass amendmentSelectionClass = new ctrl_AmendmentSelectionClass(accountExtendedObject);
        amendmentSelectionClass.searchAllAmendmentTemplateMethod();
        
        //For Account Activity Traversing...
        for(ctrl_AmendmentSelectionClass.wrapperClass traversing : amendmentSelectionClass.accountActivityItemList)
        {
            traversing.accountActivityChecked = true;
            
        }
        
        
        
        pageRef = amendmentSelectionClass.cancelPageMethod();
        
        //Query for the Record types of Amendment Object...
         Map<string,RecordType> amendmentRecordTypeMap = new Map<string,RecordType>();
        for(RecordType recordType : [Select Id,SObjectType,Name,DeveloperName from RecordType where SObjectType =: 'Amendment__c' AND IsActive =: true AND DeveloperName NOT IN ('Company_Amendment_Change_Company_Name_Read_Only','Shareholder_Amendment_Replace_Partner_ReadOnly','Shareholder_Amendment_Remove_Partner_ReadOnly')])
        {
            //Creating the New Location and Updating account because every Record Type Selection user updates the values... 
            Location__c templocationObject = new Location__c();
            templocationObject.Name = 'Test Location Vacant'+ recordType.Id;
            templocationObject.Location_Type__c = 'Land';
            templocationObject.Rental_Rate__c = 18000;
            templocationObject.Visa_Quota__c = 5;
            insert templocationObject;
            
            accountObject.Amendment_Change_Location__c = templocationObject.Id;
            update accountObject;
        
            amendmentRecordTypeMap.put(recordType.DeveloperName, recordType);
            amendmentSelectionClass.selectedRecordType = recordType.id; 
            amendmentSelectionClass.selectedLocationKey = tenancyObject.id;
            amendmentSelectionClass.selectedLocationChange = tenancyObject.id;
            amendmentSelectionClass.selectedChangeLocationOperations = 'Add';
            //Calling the Update Method...
            pageRef = amendmentSelectionClass.updateFlagsForRerenderMethod();   
            //Calling the Save Button Method...
            System.debug('The Selected Location Key => '+ amendmentSelectionClass.selectedLocationKey + ' && The Record Type Name => '+ recordType.Name);   
            pageRef = amendmentSelectionClass.saveButtonMethod();
                
                        
        }
        
        //Now Update the Amendment Location Of Account Because code change the status of Amendment Change Location...
        /*accountObject.Amendment_Change_Location__c = locationObject1.Id;
        update accountObject;*/
        
        //Location Amendment - New Key Test Case...
        /*amendmentSelectionClass.selectedRecordType = amendmentRecordTypeMap.get('Location_Amendment_New_Key').id;
        amendmentSelectionClass.selectedLocationKey = tenancyObject.id;
        pageRef = amendmentSelectionClass.saveButtonMethod();
        
        
        //Location Amendment - Change Location
        amendmentSelectionClass.selectedRecordType = amendmentRecordTypeMap.get('Location_Amendment_Change_Location').id;
        amendmentSelectionClass.selectedLocationChange = tenancyObject.id;
        pageRef = amendmentSelectionClass.saveButtonMethod();*/
        
        
        
        
                
    }
}